$(document).ready(function() {
    $( "#username" ).autocomplete({
        source: "autocomplete",
        minLength: 1
    });
    $("#loading-indicator").hide();
    $(document).bind("ajaxSend", function(){
        $("#loading-indicator").show();
    }).bind("ajaxComplete", function(){
        $("#loading-indicator").hide();
    });
    //$("#return-chat").button();
    //$('#return-home').button();
    
    $("#autocomplete").click(function(){
        $.ajax({
            type: 'POST',
            dataType: 'json',
            url: 'performDeleteUser?username='+$("#username").val(),
            timeout: 3000,
            success: function(data) {
                if(!data["error"]){
                    $("#error").html("<span class='glyphicon glyphicon-ok'></span> The user has been removed succesfully !").
                            addClass("create-error").addClass("delete-success");
                }
                else{
                   $("#error").html("<span class='glyphicon glyphicon-remove'></span> Unable to remove the user !").
                           removeClass('delete-success').addClass("delete-error"); 
                }
            },
            error: function() {
                $("#error").text("Unable to remove user !").addClass("delete-error"); 
            }
        });    
    });
});